#ifndef miscgraphics_h
#define miscgraphics_h

#include "FoodObjects/NutritionalInfo.h"
#include "juce_amalgamated.h"
#include <locale>

class MiscGraphics {
public:
	static void drawRoundedRect(Graphics& g, Rectangle& r, const float cornerRadius,
			const float lineWidth) {
		g.drawRoundedRectangle(r, cornerRadius, lineWidth);
		int buf = (int) (cornerRadius * 0.85);
		g.drawLine(r.getX(), r.getY() + buf, r.getX(), r.getY() + r.getHeight() - buf, lineWidth + 1.5);
		g.drawLine(r.getX() + buf, r.getY(), r.getX() + r.getWidth() - buf, r.getY(), lineWidth + 1.5);
		g.drawLine(r.getX() + r.getWidth(), r.getY() + buf, r.getX() + r.getWidth(), r.getY()
				+ r.getHeight() - buf, lineWidth + 1.5);
		g.drawLine(r.getX() + buf, r.getY() + r.getHeight(), r.getX() + r.getWidth() - buf, r.getY()
				+ r.getHeight(), lineWidth + 1.5);
	}

	static void drawNutritionalDiagram(NutritionalInfo& info, Graphics& g, Rectangle& r) {

		Font header(Font(Font::getDefaultSansSerifFontName(), 24, Font::bold));
		Font bold(Font(Font::getDefaultSansSerifFontName(), 16, Font::bold));
		Font plain(Font(Font::getDefaultSansSerifFontName(), 16, Font::plain));

		g.setColour(Colours::white);
		g.fillRect(r.getX() - 7, r.getY(), r.getWidth(), r.getHeight());
		g.setColour(Colours::grey);
		g.drawRect(r.getX() - 7, r.getY(), r.getWidth(), r.getHeight());
		g.setColour(Colours::black);

		g.setFont(header);
		g.drawSingleLineText(T("Nutrition Facts"), r.getX(), r.getY() + 24);

		g.setFont(plain);
		g.drawSingleLineText(String::formatted(T("Calories %d"), int(info.calories)), r.getX(), r.getY()
				+ 43);
		g.drawSingleLineText(String::formatted(T("Calories From Fat %d"), int(9 * info .totalFat)),
				r.getX() + r.getWidth() / 2 - 30, r.getY() + 43);
		g.drawHorizontalLine(r.getY() + 50, r.getX(), r.getRight() - 14);
		g.drawSingleLineText(String::formatted(T(" %3.1fg"), info.totalFat), r.getX()
				+ bold.getStringWidth(T("Total Fat")), r.getY() + 67);
		g.setFont(bold);
		g.drawSingleLineText(T("Total Fat"), r.getX(), r.getY() + 67);
		g.setFont(plain);
		g.drawSingleLineText(String::formatted(T("Saturated Fat %2.1fg"), info.saturatedFat), r.getX(),
				r.getY() + 87);
		g.drawSingleLineText(String::formatted(T("Trans Fat %2.1fg"), info.transFat), r.getX(),
				r.getY() + 107);
		g.drawHorizontalLine(r.getY() + 116, r.getX(), r.getRight() - 14);

		g.setFont(bold);
		g.drawSingleLineText(T("Cholesterol"), r.getX(), r.getY() + 137);
		g.setFont(plain);
		g.drawSingleLineText(String::formatted(T(" %dmg"), int(info.cholesterol)), r.getX()
				+ bold.getStringWidth(T("Cholesterol")), r.getY() + 137);

		g.setFont(bold);
		g.drawSingleLineText(T("Sodium"), r.getX(), r.getY() + 157);
		g.setFont(plain);
		g.drawSingleLineText(String::formatted(T(" %dmg"), int(info.sodium)), r.getX()
				+ bold.getStringWidth(T("Sodium")), r.getY() + 157);

		g.drawHorizontalLine(r.getY() + 165, r.getX(), r.getRight() - 14);
		g.setFont(bold);
		g.drawSingleLineText(T("Total Carbohydrate"), r.getX(), r.getY() + 187);
		g.setFont(plain);
		g.drawSingleLineText(String::formatted(T(" %3.1fg"), info.totalCarb), r.getX()
				+ bold.getStringWidth(T("Total Carbohydrate")), r.getY() + 187);
		g.drawSingleLineText(String::formatted(T("Dietary Fibre %3.1fg"), info.fibre), r.getX(),
				r.getY() + 207);
		g.drawSingleLineText(String::formatted(T("Sugars %3.1fg"), info.sugar), r.getX(), r.getY()
				+ 227);

		g.setFont(bold);
		g.drawSingleLineText(T("Protein"), r.getX(), r.getY() + 247);
		g.setFont(plain);
		g.drawSingleLineText(String::formatted(T(" %dg"), int(info.protein)), r.getX()
				+ bold.getStringWidth(T("Protein")), r.getY() + 247);

		g.drawHorizontalLine(r.getY() + 255, r.getX(), r.getRight() - 14);
		g.drawSingleLineText(String::formatted(T("Vitamin A %d\u03bcg"), int(info.vitaminA)), r.getX(),
				r.getY() + 277);
		g.drawSingleLineText(String::formatted(T("Vitamin C %d\u03bcg"), int(info.vitaminC)), r.getX()
				+ r.getWidth() / 2, r.getY() + 277);
		g.drawSingleLineText(String::formatted(T("Vitamin D %d\u03bcg"), int(info.vitaminD)), r.getX(),
				r.getY() + 297);
		g.drawSingleLineText(String::formatted(T("Calcium %dmg"), int(info.calcium)), r.getX(),
				r.getY() + 317);
		g.drawSingleLineText(String::formatted(T("Iron %2.1fmg"), info.iron), r.getX() + r.getWidth()
				/ 2, r.getY() + 317);
		g.drawHorizontalLine(r.getY() + 325, r.getX(), r.getRight() - 14);
		g.drawSingleLineText(String::formatted(T("Caffeine %2.1fmg"), info.caffeine), r.getX(),
				r.getY() + 347);
	}
};

#endif
